package com.campusnews.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.campusnews.annotation.LoginToken;
import com.campusnews.pojo.Invitation;
import com.campusnews.pojo.dayData;
import com.campusnews.pojo.Thing;
import com.campusnews.service.InvitationService;
import com.campusnews.utils.JsonResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lqc
 * @since 2021-09-26
 */
@RestController
@ApiOperation(value = "帖子API", notes = "帖子API")
@RequestMapping("/invitation")
@Api(tags={"帖子API"})
public class InvitationController {

    @Autowired
    private InvitationService invitationService;


//    @LoginToken
//    @ApiOperation(value = "修改帖子信息", notes = "修改帖子信息")
//    @RequestMapping(value = "/updateInvite" ,method = RequestMethod.POST)
//    public JsonResult updateInvite(@RequestBody Invitation invitation) {
//        boolean update = invitationService.saveOrUpdate(invitation);
//        if (update){
//            return JsonResult.build(200,"帖子修改成功",update);
//        }else {
//            return JsonResult.errorMsg("帖子修改失败");
//        }
//    }
//
//    @LoginToken
//    @ApiOperation(value = "添加帖子信息", notes = "添加帖子信息")
//    @RequestMapping(value = "/insertInvite" ,method = RequestMethod.POST)
//    public JsonResult insertInvite(@RequestBody Invitation invitation) {
//        boolean insertInvite = invitationService.insertInvite(invitation);
//        if (insertInvite){
//            return JsonResult.build(200,"帖子添加成功",insertInvite);
//        }else {
//            return JsonResult.errorMsg("帖子添加失败");
//        }
//    }

    @LoginToken
    @ApiOperation(value = "删除帖子信息", notes = "删除帖子信息")
    @RequestMapping(value = "/deleteInvite/{inviId}" ,method = RequestMethod.GET)
    public JsonResult deleteInvite(@PathVariable("inviId")int inviId) {
        QueryWrapper<Invitation> wrapper = new QueryWrapper<>();
        wrapper.eq("invi_id",inviId);
        boolean remove = invitationService.remove(wrapper);
        if (remove){
            return JsonResult.build(200,"帖子删除成功",remove);
        }else {
            return JsonResult.errorMsg("帖子删除失败");
        }
    }

//    @LoginToken
    @ApiOperation(value = "分页精确查询帖子信息", notes = "分页精确帖子信息")
    @RequestMapping(value = "/selectInviteByAccurate" ,method = RequestMethod.POST)
    public JsonResult selectInviteByAccurate(@RequestBody Invitation invitation) {
        PageInfo<Invitation> pageInfo = invitationService.selectInviteByAccurate(invitation);
        if (pageInfo.getList().size()==0){
            return JsonResult.errorMsg("查询不到数据");
        }
        return JsonResult.build(200,"分页精确查询帖子信息成功",pageInfo);
    }

    @LoginToken
    @ApiOperation(value = "分页模糊查询帖子信息", notes = "分页模糊帖子信息")
    @RequestMapping(value = "/selectInviteByVague" ,method = RequestMethod.POST)
    public JsonResult selectInviteByVague(@RequestBody Thing things) {
        PageInfo<Invitation> pageInfo = invitationService.selectInviteByVague(things);
        if (pageInfo.getList().size()==0){
            return JsonResult.errorMsg("查询不到数据");
        }
        return JsonResult.build(200,"分页模糊帖子信息查询成功",pageInfo);
    }

}

